package org.streets.eis.component.modal;

import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.util.string.Strings;

public class ModalDialog extends ModalWindow {

	private static final long serialVersionUID = 1L;

	public ModalDialog(String id) {
		super(id);
	}
	
	public void showPage(String title,final Page page,AjaxRequestTarget target,
			ModalWindow.WindowClosedCallback closedCallback,
			ModalWindow.CloseButtonCallback closeButtonCallback,
			int minWidth,int minHeight,int initWidth,int initHeight){
		
		setPageCreator(new PageCreator(){
			private static final long serialVersionUID = 1L;
			public Page createPage() {
				return page;
			}			
		});
		
		if (!Strings.isEmpty(title)) { 
			setTitle(title);
		}
		
		if (closedCallback!=null){
			setWindowClosedCallback(closedCallback);
		}
		
		if (closeButtonCallback!=null){
			setCloseButtonCallback(closeButtonCallback);
		}
		
		if (minWidth>0){
			setMinimalWidth(minWidth);
		}
		
		if (minHeight>0){
			setMinimalHeight(minHeight);
		}
		
		if (initWidth>0){
			setInitialWidth(initWidth);
		}
		
		if (initHeight>0){
			setInitialHeight(initHeight);
		}
		
		show(target);
	}
	
	public void showPage(String title,final Page page,AjaxRequestTarget target,
			ModalWindow.WindowClosedCallback closedCallback,
			ModalWindow.CloseButtonCallback closeButtonCallback){
		showPage(title,page,target,closedCallback,closeButtonCallback,0,0,0,0);
	}
	
	public void showPage(String title,final Page page,AjaxRequestTarget target,
			ModalWindow.WindowClosedCallback closedCallback){
		showPage(title,page,target,closedCallback,null,0,0,0,0);
	}
	
	public void showPage(String title,final Page page,AjaxRequestTarget target){
		showPage(title,page,target,null,null,0,0,0,0);
	}
	
	public void showPage(final Page page,AjaxRequestTarget target){
		showPage(null,page,target,null,null,0,0,0,0);
	}	
	
}
